/* -----------------------------------------------------------------------
 * Becky Kluth
 * CS 362
 * Assignment 3: unittest4.c test of function gainCard() in dominion.c
 *
 * unittest4: unittest4.c dominion.o rngs.o
 *      gcc -o unittest4 -g  unittest4.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

//set NOISY_TEST to 0 to remove printfs from output (this macro take from the example)
#define NOISY_TEST 0

int main() {
	int seed = 1000;										//initiate a two player game
    int numPlayer = 2;
    int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
    struct gameState G;
	int crash;
	int startingHandCount, startingSupplyCount;

    initializeGame(numPlayer, k, seed, &G);

    printf ("Testing gainCard():\n");

	startingHandCount = G.handCount[0];
	startingSupplyCount = G.supplyCount[0];
#if (NOISY_TEST == 1)
	printf("Start hand count: %d, supply count: %d\n", startingHandCount, startingSupplyCount);
#endif
	crash = gainCard(0, &G, 2, 0);							//player 0 gains adventurer card to hand
	assert(crash == 0);
	assert(G.handCount[0] == startingHandCount + 1);		//+1 card in hand
	assert(G.supplyCount[0] == startingSupplyCount - 1);	//-1 card in adventurer supply
#if (NOISY_TEST == 1)
	printf("End hand count: %d, supply count: %d\n", G.handCount[0], G.supplyCount[0]);
#endif

	G.supplyCount[0] = 0;									//no more adventurer cards left
	startingHandCount = G.handCount[0];
	startingSupplyCount = G.supplyCount[0];
#if (NOISY_TEST == 1)
	printf("Start hand count: %d, supply count: %d\n", startingHandCount, startingSupplyCount);
#endif
	crash = gainCard(0, &G, 2, 0);							//player 0 gains adventurer card to hand
	assert(crash == -1);									//shouldn't be allowed
	assert(G.handCount[0] == startingHandCount);			//no change in hand
	assert(G.supplyCount[0] == startingSupplyCount);		//no change in adventurer supply
#if (NOISY_TEST == 1)
	printf("End hand count: %d, supply count: %d\n", G.handCount[0], G.supplyCount[0]);
#endif

    printf("All tests passed!\n");

    return 0;
}